﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WaterKit.DbBase;
using WaterKit.Base;
using System.Data;

namespace Auction_Server.Business
{
    /// <summary>
    /// 拍卖会服务
    /// </summary>
    public class auctionService : OracleHelper
    {
        /// <summary>
        /// 根据拍卖会编号获取拍卖会信息
        /// </summary>
        /// <param name="auction_no">拍卖会编号</param>
        /// <returns></returns>
        public DataTable getAuction(string auction_no)
        {
            try
            {
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM  AUCTION WHERE AUCTION_NO = '").Append(auction_no).Append("'");
                DataTable dt = RetriveDataTable(sql.ToString());
                return dt.Rows.Count == 1 ? dt : null;
            }
            catch (Exception ex)
            {
                Log4C.WriteErrLog("根据拍卖会编号获取拍卖会信息", ex);
                return null;
            }
        }

        /// <summary>
        /// 获取当前日期的拍卖会
        /// </summary>
        /// <param name="auctionDate">拍卖会日期</param>
        /// <param name="auctionStatus">拍卖会状态</param>
        /// <returns>DataTable</returns>
        public DataTable getAuctionLst(String auctionDate, String auctionStatus)
        {
            try
            {
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM AUCTION WHERE  TO_CHAR(AUCTION_DATE,'YYYY-MM-DD') = '");
                sql.Append(auctionDate).Append("' AND DEL_FLG='0' AND AUCTION_STATUS='");
                sql.Append(auctionStatus).Append("'");
                return RetriveDataTable(sql.ToString());
            }
            catch (Exception ex)
            {
                Log4C.WriteErrLog("系统无法正常获取当前日期的拍卖会列表。", ex);
                return null;
            }
        }

        /// <summary>
        /// 更新拍卖会状态
        /// </summary>
        /// <param name="auction_no">拍卖会编号</param>
        /// <param name="status">状态</param>
        /// <returns>布尔</returns>
        public bool setAuctionStatus(string auction_no, string status)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("UPDATE auction SET AUCTION_STATUS='");
            sql.Append(status).Append("'");
            sql.Append(" WHERE AUCTION_NO='").Append(auction_no).Append("'");

            return queryNonSQL(sql.ToString());
        }
    }
}
